var t = require;
var e = module;
var o = exports;
var _n16,
    i =
        (this && this.__extends) ||
        ((_n16 = function n(t, e) {
            return (_n16 =
                Object.setPrototypeOf ||
                ({__proto__: []} instanceof Array &&
                    function (t, e) {
                        t.__proto__ = e;
                    }) ||
                function (t, e) {
                    for (var o in e) {
                        Object.prototype.hasOwnProperty.call(e, o) && (t[o] = e[o]);
                    }
                })(t, e);
        }),
        function (t, e) {
            function o() {
                this.constructor = t;
            }
            _n16(t, e), (t.prototype = null === e ? Object.create(e) : ((o.prototype = e.prototype), new o()));
        });
Object.defineProperty(o, "__esModule", {value: !0});
var s = t("BaseSdk"),
    r = t("SDKEvent"),
    c = t("Common"),
    a = t("Global"),
    u = (function (t) {
        function e() {
            var e = (null !== t && t.apply(this, arguments)) || this;
            return (
                (e._recorderShareFunc = null),
                (e._musicPauseFunc = null),
                (e._musicPauseThis = null),
                (e._musicResumeFunc = null),
                (e._musicResumeThis = null),
                (e._clipboardData = ""),
                (e._playScreenTime = 0),
                (e._screenSpaceTime = 0),
                (e._interstitiaId = ""),
                (e._moreGameBtn = null),
                (e._recorder = null),
                (e.lastAdTime = 0),
                (e._recorderStatus = 0),
                (e._recorderEndTime = 0),
                (e._recorderTime = 0),
                (e._videoId = "30993f80afde5cad33485f7e90ddf0d9"),
                (e._bannerId = "adunit-379f013d20d019c6"),
                (e._screenId = "d9cc5fea125be842e97ec5ac0408c464"),
                (e._screenId2 = "d9cc5fea125be842e97ec5ac0408c464"),
                (e._portalId = "PBgAAwpm9LNY17Dc"),
                (e._shareId = "cPtOicL/Rcq/M4860CbA0g=="),
                (e._shareTitle = "粉碎球球"),
                (e._shareDesc = "一起来粉碎球球吧"),
                (e._videoLoaded = !1),
                (e._videoOptions = null),
                (e._videoAd = null),
                (e._bannerLoaded = !1),
                (e.gridAd = null),
                (e.banner = null),
                (e.singleCustomAd = null),
                (e.rightButtomCustomAd = null),
                (e.leftCustomAd = null),
                (e.rightCustomAd = null),
                (e.lastshockTime = 0),
                (e.shareBtn = null),
                (e.screenShow = !0),
                (e.launchInfo = ""),
                (e.serverScene = [1011, 1012, 1047, 1048, 2005, 2077]),
                e
            );
        }
        return (
            i(e, t),
            (e.prototype.init = function () {
                var t = this,
                    e = this;
                (this.lastAdTime = new Date().getTime()),
                    qq.showShareMenu(),
                    qq.onShareAppMessage(function (t) {
                        return (
                            console.log("监听到分享事件", t),
                            {
                                title: e._shareTitle,
                                query: "",
                                success: function success() {
                                    console.log("分享成功");
                                },
                                fail: function fail(t) {
                                    console.log("分享失败", t);
                                }
                            }
                        );
                    });
                var o = qq.getUpdateManager();
                o.onCheckForUpdate(function (t) {
                    console.log(t.hasUpdate);
                }),
                    o.onUpdateReady(function () {
                        qq.showModal({
                            title: "更新提示",
                            content: "新版本已经准备好，是否立即使用？",
                            showCancel: !1,
                            success: function success() {
                                o.applyUpdate();
                            }
                        });
                    }),
                    o.onUpdateFailed(function () {}),
                    this._preloadVideo(),
                    this.loadCustomAd(),
                    this.showCustomAd(),
                    (this.launchInfo = qq.getLaunchOptionsSync());
                var n = this.launchInfo.scene >> 0,
                    i = c.default.host + "/getConfig";
                this.sendHttpRequest(
                    i,
                    {app: "cfg_des_ball"},
                    function (e) {
                        "true" == e.config.open_ad
                            ? ((a.default.wuchu = !0),
                              t.serverScene.indexOf(n) >= 0 && (console.log("关闭广告"), (a.default.wuchu = !1)))
                            : (a.default.wuchu = !1),
                            e.config.wcncount && (a.default.wuchuNextCount = e.config.wcncount >> 0),
                            e.config.wcrcount && (a.default.wuchuRestartCount = e.config.wcrcount >> 0);
                    },
                    function () {}
                );
            }),
            (e.prototype._preloadVideo = function () {
                var t = this;
                (this._videoAd = qq.createRewardedVideoAd({adUnitId: t._videoId})),
                    this._videoAd.onLoad(function () {
                        t._videoLoaded = !0;
                    }),
                    this._videoAd.load().then(function () {
                        t._videoLoaded = !0;
                    }),
                    this._videoAd.onClose(function (e) {
                        (t._videoLoaded = !1),
                            (t.lastAdTime = new Date().getTime()),
                            e.isEnded
                                ? t._videoOptions && t._videoOptions.success && t._videoOptions.success()
                                : qq.showModal({
                                      title: "奖励提醒",
                                      content: "中途关闭视频无法获得奖励，是否继续获得奖励？",
                                      success: function success(e) {
                                          e.confirm ? t.showRewardVideo(t._videoOptions) : e.cancel;
                                      },
                                      fail: function fail() {
                                          console.log("showModal调用失败");
                                      }
                                  }),
                            t._videoAd.load().then(function () {
                                console.log("广告关闭后重新加载成功"), (t._videoLoaded = !0);
                            });
                    }),
                    this._videoAd.onError(function (e) {
                        (t._videoLoaded = !1),
                            console.log("加载失败，尝试重试", e),
                            setTimeout(function () {
                                t._videoAd.load().then(function () {
                                    t._videoLoaded = !0;
                                });
                            }, 3e4);
                    });
            }),
            (e.prototype.loadCustomAd = function () {
                var t = this,
                    e = qq.getSystemInfoSync(),
                    o = e.windowWidth,
                    n = e.windowHeight,
                    i = qq.getSystemInfoSync().SDKVersion,
                    s = new RegExp("\\.", "g");
                (i = i.replace(s, "")),
                    parseInt(i) >= 1150 &&
                        (console.log("加载积木广告"),
                        (this.singleCustomAd = qq.createBlockAd({
                            adUnitId: "db8c3bfe4a465e959a59ad60e83d18bf",
                            size: 1,
                            orientation: "landscape",
                            style: {left: 20, top: n / 2 - 50}
                        })),
                        this.singleCustomAd.onResize(function (e) {
                            var o = e.height;
                            (t.singleCustomAd.style.left = 20), (t.singleCustomAd.style.top = n / 2 - o / 2);
                        }),
                        this.singleCustomAd.onLoad(function () {
                            console.log("单个积木加载成功"), a.default.yinsi && t.singleCustomAd.show();
                        }),
                        this.singleCustomAd.onError(function (t) {
                            console.log("单个积木加载失败", t);
                        }),
                        (this.rightButtomCustomAd = qq.createBlockAd({
                            adUnitId: "e1fe473ca92324684869a99eca63cdf9",
                            size: 5,
                            orientation: "landscape",
                            style: {left: o - 300, top: n - 200}
                        })),
                        this.rightButtomCustomAd.onResize(function (e) {
                            var i = e.width,
                                s = e.height;
                            console.log("积木广告长宽", s, i),
                                (t.rightButtomCustomAd.style.left = o - i),
                                (t.rightButtomCustomAd.style.top = n - s - s / 5);
                        }),
                        this.rightButtomCustomAd.onLoad(function () {
                            console.log("右下积木加载成功"), a.default.yinsi && t.rightButtomCustomAd.show();
                        }),
                        this.rightButtomCustomAd.onError(function (t) {
                            console.log("右下积木加载失败", t);
                        }),
                        (this.leftCustomAd = qq.createBlockAd({
                            adUnitId: "863ff485422db914f71ac6f24628d1c6",
                            size: 5,
                            orientation: "vertical",
                            style: {left: 20, top: n / 2 - 150}
                        })),
                        this.leftCustomAd.onResize(function (e) {
                            var o = e.height;
                            t.leftCustomAd.style.top = n / 2 - o / 2;
                        }),
                        this.leftCustomAd.onLoad(function () {
                            console.log("左边积木加载成功");
                        }),
                        this.leftCustomAd.onError(function (t) {
                            console.log("左边积木加载失败", t);
                        }),
                        (this.rightCustomAd = qq.createBlockAd({
                            adUnitId: "688908206b6add026b59bc6ee972f107",
                            size: 5,
                            orientation: "vertical",
                            style: {left: o - 300, top: n / 2 - 150}
                        })),
                        this.rightCustomAd.onResize(function (e) {
                            var i = e.width,
                                s = e.height;
                            (t.rightCustomAd.style.left = o - i), (t.rightCustomAd.style.top = n / 2 - s / 2);
                        }),
                        this.rightCustomAd.onLoad(function () {
                            console.log("右边积木加载成功");
                        }),
                        this.rightCustomAd.onError(function (t) {
                            console.log("右边积木加载失败", t);
                        }));
            }),
            (e.prototype.showCustomAd = function () {
                this.singleCustomAd && this.singleCustomAd.show(),
                    this.rightButtomCustomAd && this.rightButtomCustomAd.show();
            }),
            (e.prototype.hideCustomAd = function () {
                this.singleCustomAd && this.singleCustomAd.hide(),
                    this.rightButtomCustomAd && this.rightButtomCustomAd.hide();
            }),
            (e.prototype.showCustomAdBig = function () {
                this.leftCustomAd && this.leftCustomAd.show(), this.rightCustomAd && this.rightCustomAd.show();
            }),
            (e.prototype.hideCustomAdBig = function () {
                this.leftCustomAd && this.leftCustomAd.hide(), this.rightCustomAd && this.rightCustomAd.hide();
            }),
            (e.prototype.loadBanner = function () {
                var t = this;
                this.banner && (this.banner.destroy(), (this.banner = null));
                var e = qq.getSystemInfoSync(),
                    o = e.windowWidth,
                    n = e.windowHeight;
                (this.banner = qq.createBannerAd({
                    adUnitId: t._bannerId,
                    style: {width: 200, height: 100, left: (o - 200) / 2, top: n - 112.5}
                })),
                    this.banner.onLoad(function () {
                        (t._bannerLoaded = !0),
                            t.banner.show(),
                            setTimeout(function () {
                                t.loadBanner();
                            }, 6e4);
                    }),
                    this.banner.onError(function () {
                        t._bannerLoaded = !1;
                    }),
                    this.banner.onResize(function (e) {
                        console.log(e.width, o, e.height, n),
                            (t.banner.style.top = n - e.height),
                            (t.banner.style.left = (o - e.width) / 2);
                    });
            }),
            (e.prototype.showBanner = function () {
                try {
                    Math.random() < 0.5
                        ? this.banner
                            ? this.banner.show()
                            : this.gridAd && this.gridAd.show()
                        : this.gridAd
                        ? this.gridAd.show()
                        : this.banner && this.banner.show();
                } catch (t) {}
            }),
            (e.prototype.hideBanner = function () {
                try {
                    this.banner && this.banner.hide(), this.gridAd && this.gridAd.hide();
                } catch (t) {}
            }),
            (e.prototype.setKeepScreenOn = function (t) {
                qq.setKeepScreenOn(t);
            }),
            (e.prototype.getUserInfo = function (t) {
                qq.login({
                    success: function success(e) {
                        var o = e.code;
                        qq.authorize({
                            scope: "scope.userInfo",
                            success: function success() {
                                qq.getUserInfo({
                                    success: function success(e) {
                                        t.success(e.userInfo, o);
                                    },
                                    fail: function fail() {
                                        t.fail(o);
                                    }
                                });
                            },
                            fail: function fail(e) {
                                console.log("授权获取用户信息失败: " + JSON.stringify(e)), t.fail(o);
                            },
                            complete: function complete() {
                                console.log("授权获取用户信息完成");
                            }
                        });
                    },
                    fail: function fail() {
                        console.log("login调用失败"), t.fail();
                    }
                });
            }),
            (e.prototype.login = function (t) {
                var e = this;
                console.log("头条登录"),
                    qq.login({
                        force: t.force,
                        success: function success(o) {
                            console.log("login调用成功", o);
                            var n = o.code,
                                i = o.anonymousCode;
                            if (o.isLogin)
                                qq.getUserInfo({
                                    success: function success(o) {
                                        var i = JSON.stringify(o.userInfo),
                                            s = {code: n, json: i, visitor: !1};
                                        e.sendHttpRequest(
                                            c.default.ttLoginUrl,
                                            s,
                                            function (e) {
                                                var o = e.data;
                                                0 == o.user.status
                                                    ? (console.log("登录完成，准备回调"), t.success(o))
                                                    : (console.log("用户状态异常"),
                                                      t.fail("你因违规操作,帐号已被系统冻结"));
                                            },
                                            function (e) {
                                                console.log("request调用失败", e), t.fail("网络繁忙,请稍后再试");
                                            }
                                        );
                                    },
                                    fail: function fail(o) {
                                        console.log("getUserInfo 调用失败", o);
                                        var n = {code: i, json: "{}", visitor: !0};
                                        e.sendHttpRequest(
                                            c.default.ttLoginUrl,
                                            n,
                                            function (e) {
                                                var o = e.data;
                                                0 == o.user.status
                                                    ? (console.log("登录完成，准备回调"), t.success(o))
                                                    : (console.log("用户状态异常"),
                                                      t.fail("你因违规操作,帐号已被系统冻结"));
                                            },
                                            function (e) {
                                                console.log("request调用失败", e), t.fail("网络繁忙,请稍后再试");
                                            }
                                        );
                                    }
                                });
                            else {
                                var s = {code: i, json: "{}", visitor: !0};
                                e.sendHttpRequest(
                                    c.default.ttLoginUrl,
                                    s,
                                    function (e) {
                                        var o = e.data;
                                        0 == o.user.status
                                            ? (console.log("登录完成，准备回调"), t.success(o))
                                            : (console.log("用户状态异常"), t.fail("你因违规操作,帐号已被系统冻结"));
                                    },
                                    function (e) {
                                        console.log("request调用失败", e), t.fail("网络繁忙,请稍后再试");
                                    }
                                );
                            }
                        },
                        fail: function fail(e) {
                            console.log("login调用失败", e), t.fail("登录失败,请稍后再试");
                        }
                    });
            }),
            (e.prototype.createMoreGamesButton = function () {
                var t = this;
                console.log("创建游戏盒子"),
                    this._moreGameBtn
                        ? this._moreGameBtn.show()
                        : ((this._moreGameBtn = qq.createAppBox({adUnitId: "ee1dcfe40370c223f965f1856cca60d7"})),
                          this._moreGameBtn.load().then(function () {
                              t._moreGameBtn.show();
                          }));
            }),
            (e.prototype.getOpenDataContext = function () {}),
            (e.prototype.postMessage = function () {}),
            (e.prototype.startRecorder = function () {
                this._recorder &&
                    !this._isRecorder &&
                    (console.log("准备开始录屏"),
                    (this._recorderTime = new Date().getTime()),
                    (this._isRecorder = !0),
                    this._recorder.start({duration: 60}),
                    cc.systemEvent.emit(r.default.CHANGE_RECORDER_STATE));
            }),
            (e.prototype.stopRecorder = function (t) {
                this._recorder &&
                    this._isRecorder &&
                    (console.log("准备停止录屏"),
                    (this._recorderEndTime = new Date().getTime()),
                    (this._recorderShareFunc = t),
                    this._recorder.stop(),
                    (this._isRecorder = !1),
                    cc.systemEvent.emit(r.default.CHANGE_RECORDER_STATE));
            }),
            (e.prototype.getRecorderTime = function () {
                return this._recorderEndTime - this._recorderTime;
            }),
            (e.prototype.getIsScreenRecordVideo = function () {
                return !1;
            }),
            (e.prototype.getRecorderState = function () {
                return this._isRecorder;
            }),
            (e.prototype.showShareBtn = function () {}),
            (e.prototype.hideShareBtn = function () {}),
            (e.prototype.shareRecorder = function (t) {
                var e = t.query;
                qq.shareAppMessage({
                    channel: "video",
                    title: this._shareTitle,
                    desc: this._shareDesc,
                    templateId: this._shareId,
                    query: e,
                    success: function success(e) {
                        console.log("分享视频成功"), t.success && t.success(e.videoId);
                    },
                    fail: function fail(e) {
                        console.log("分享视频失败", e), t.fail && t.fail(e);
                    },
                    complete: function complete() {}
                });
            }),
            (e.prototype.showRewardVideo = function (t) {
                var e = this;
                if (!e._videoAd) return t && t.success && t.success();
                (e._videoOptions = t),
                    e._videoAd
                        .show()
                        .then(function () {})
                        .catch(function () {
                            e._videoAd.load().then(function () {
                                return e._videoAd.show();
                            });
                        });
            }),
            (e.prototype.setClipboardData = function (t) {
                qq.setClipboardData({
                    data: t.data,
                    success: function success() {
                        t.success && t.success(), console.log("调用剪切板成功", t.data);
                    },
                    fail: function fail() {
                        t.fail && t.fail(), console.log("调用剪切板失败", t.data);
                    }
                });
            }),
            (e.prototype.getVideoState = function () {
                return this._videoLoaded;
            }),
            (e.prototype.playScreen = function (t) {
                void 0 === t && (t = 1);
                var e = this;
                if (new Date().getTime() - this.lastAdTime > 6e4) {
                    var o = qq.createInterstitialAd({adUnitId: 1 == t ? e._screenId : e._screenId2});
                    o.onClose(function () {
                        e.lastAdTime = new Date().getTime();
                    }),
                        o.onLoad(function () {
                            console.log("QQ插屏加载成功");
                        }),
                        o.onError(function (t) {
                            console.log("QQ插屏加载失败", t);
                        }),
                        o.show().catch(function (t) {
                            console.log("QQ显示插屏失败", t);
                        });
                }
            }),
            (e.prototype.sendEvent = function (t) {
                t &&
                    t.key &&
                    (console.log("上报事件:", t.key),
                    t.value ? qq.reportAnalytics(t.key, t.value) : qq.reportAnalytics(t.key, {}));
            }),
            (e.prototype.vibrateShort = function () {
                var t = new Date().getTime();
                t - this.lastshockTime > 100 &&
                    ((this.lastshockTime = t),
                    qq.vibrateShort({
                        success: function success() {},
                        fail: function fail() {
                            console.log("vibrateShort调用失败");
                        }
                    }));
            }),
            (e.prototype.vibrateLong = function () {
                qq.vibrateLong({
                    success: function success() {},
                    fail: function fail() {
                        console.log("vibrateLong调用失败");
                    }
                });
            }),
            (e.prototype.showToast = function (t) {
                qq.showToast({
                    title: t,
                    icon: "none",
                    duration: 2e3,
                    success: function success() {},
                    fail: function fail() {}
                });
            }),
            (e.prototype.showLoading = function (t) {
                qq.showLoading({title: t});
            }),
            (e.prototype.hideLoading = function () {
                qq.hideLoading();
            }),
            (e.prototype.share = function (t) {
                qq.shareAppMessage(t);
            }),
            (e.prototype.setLocalStorage = function (t, e) {
                cc.sys.localStorage.setItem(t, e);
            }),
            (e.prototype.getLocalStorage = function (t) {
                return cc.sys.localStorage.getItem(t);
            }),
            (e.prototype.sendHttpRequest = function (t, e, o, n) {
                qq.request({
                    url: t,
                    data: e,
                    success: function success(t) {
                        if (t.data.ok) {
                            if (o) {
                                var e = t.data;
                                o(e);
                            }
                        } else n && n(t.data.msg);
                    },
                    fail: function fail(t) {
                        console.log("request调用失败", t), n && n("网络繁忙,请稍后再试");
                    }
                });
            }),
            (e.prototype.contentSafe = function (t) {
                var e = {text: t.content};
                this.sendHttpRequest(
                    c.default.contentSafeTT,
                    e,
                    function (e) {
                        e.valid ? t.callBack(!0) : t.callBack(!1);
                    },
                    function () {
                        t.callBack(!1);
                    }
                );
            }),
            (e.prototype.onShow = function (t) {
                var e = this;
                qq.onShow(function (o) {
                    var n = o.scene;
                    e.serverScene[n] && (a.default.wuchu = !1), t(o);
                });
            }),
            (e.prototype.getLaunchOptionsSync = function () {
                return this.launchInfo;
            }),
            e
        );
    })(s.default);
o.default = u;
